package com.example.ai.tool;

import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;

import com.example.ai.constant.FileConstant;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;

public class ResourceDowmloadTool {

    @Tool(description = "download resource from url")
    public String downloadResource(@ToolParam(description = "Url of the resource todowmload") String url,
                                   @ToolParam(description = "name of the file to save the download resouce ") String fileName){
        String fileDir = FileConstant.FILE_SAVE_DIR+"/download/";
        String filePath = fileDir+fileName;
        try {
            FileUtil.mkdir(fileDir);
            HttpUtil.downloadFile(url,filePath);
            return "resource download success to "+filePath;
        }catch (Exception e){
            return "resource download failed"+e.getMessage();
        }

    }
}
